
import processing.net.*;

Client client;
String data;
long counter;

void setup()
{
  size(200, 200);
  background(50);
  fill(200);
  client = new Client(this, "192.168.1.100", 2000); // Connect to robot on port 2000
  counter = millis();
}

void draw() {
  while(client.available() > 0)  // If there's incoming data from the client...
  {
    data = client.readString(); // ...then grab it and print it
    println(data);
  }
  
  if(millis() - counter > 500)
  {
    if(keyPressed)
    {
      switch(key)
      {
        
        case 'w':
          client.write("#MF");
          client.write(0x00);
          client.write(0x02);
          client.write(3);
          client.write(0);
          client.write(0x0A);
          break;
          
        case 's':
          client.write("#MB");
          client.write(0x00);
          client.write(0x01);
          client.write(4);
          client.write(0x0A);
          break;
          
        case 'a':
          client.write("#ML");
          client.write(0x00);
          client.write(0x01);
          client.write(4);
          client.write(0x0A);
          break;
          
        case 'd':
          client.write("#MR");
          client.write(0x00);
          client.write(0x01);
          client.write(4);
          client.write(0x0A);
          break;
      }
      counter = millis();
    }
  }
}

